<?php
class ModelAccountRecharge extends Model {
    public function addRecharge($data){
        $this->db->query("INSERT INTO " . DB_PREFIX . "recharge_order SET customer_id = '" . (int)$this->customer->getId() . "', price = '" . $this->db->escape($data['price']) . "', type = '" . $this->db->escape($data['type']) . "', date=NOW()");

        $recharge_id = $this->db->getLastId();

        return $recharge_id;
    }
    public function confirm($recharge_order_id,$status){
        $this->db->query("UPDATE " . DB_PREFIX . "recharge_order SET status = '" . (int)$status . "' WHERE recharge_order_id=".$recharge_order_id."");
    }

    public function getRechargeHistorys($data) {
        $sql = "SELECT o.*  FROM `" . DB_PREFIX . "recharge_order` o ";
        $sql .= " WHERE o.status > 0 AND customer_id='".$this->customer->getId()."'";
        $sql .= " ORDER BY o.recharge_order_id";
        $sql .= " ASC";


        if (isset($data['start']) || isset($data['limit'])) {
            if ($data['start'] < 0) {
                $data['start'] = 0;
            }

            if ($data['limit'] < 1) {
                $data['limit'] = 20;
            }

            $sql .= " LIMIT " . (int)$data['start'] . "," . (int)$data['limit'];
        }

        $query = $this->db->query($sql);

        return $query->rows;
    }

    public function getTotalRechargeHistorys() {
        $sql = "SELECT COUNT(*) AS total FROM `" . DB_PREFIX . "recharge_order`";
        $sql .= " WHERE status > 0 AND customer_id='".$this->customer->getId()."'";
        $sql .= " ORDER BY recharge_order_id";
        $sql .= " ASC";
        $query = $this->db->query($sql);

        return $query->row['total'];
    }




}
?>